package com.itheima.tlias84.utils;

import lombok.Data;

/**
 * 返回值工具类
 */
@Data
public class ResultUtil {
    private ResultUtil(){

    }
    private Integer code;
    private String msg;
    private Object data;
    /**
     * 默认成功方法
     */
    public static ResultUtil success(){
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg = "success";
        return resultUtil;
    }

    /**
     * 携带自定义成功信息的返回方法
     * @param message
     * @return
     */
    public static ResultUtil success(String message){
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg = message;
        return resultUtil;
    }

    /**
     * 携带数据的成功方法
     * @param data
     * @return
     */
    public static ResultUtil success(Object data){
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 1;
        resultUtil.msg ="success";
        resultUtil.data = data;
        return resultUtil;
    }

    public static ResultUtil fail(){
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg = "false";
        return resultUtil;
    }

    /**
     * 携带自定义成功信息的返回方法
     * @param message
     * @return
     */
    public static ResultUtil fail(String message){
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg = message;
        return resultUtil;
    }

    /**
     * 携带数据的成功方法
     * @param data
     * @return
     */
    public static ResultUtil fail(Object data){
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code = 0;
        resultUtil.msg ="false";
        resultUtil.data = data;
        return resultUtil;
    }

}
